package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DbConnection {
	
	private static Connection conn = null;
	
	private static String serverHost = "localhost";
	private static int serverPort = 3306;
	
	private static String database = "betyourtrain";
	private static String username = "betyourtrain";
	private static String password = "betyourtrain";
	
	public static Connection getInstance() {
		
		if (conn == null) {
			try {
				Class.forName("org.mariadb.jdbc.Driver");
				String url = "jdbc:mysql://" + serverHost + ":" + serverPort + "/" + database;
				conn = DriverManager.getConnection(url, username, password);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return conn;
	}
	
	public static void close() {
		
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
			conn = null;
		}
	}
}
